<?php
/**
 * 会员日志
 */
namespace App\Http\Controllers;

use App\Validation\MemberLogAppValidation;
use App\Service\MemberLogService;
use App\Validation\DeleteValidation;
use App\Validation\MemberVisitValidation;

class MemberLogController extends BaseController
{

	/**
	 * [indexAction 日志列表]
	 * p:当前页数
	 * page_num:每页数量
	 * pos:1登录,2搜索关键词,3停留页面,4支付,5浏览记录
	 * @return [type] [description]
	 */
	public function indexAction()
	{
		$this->getUser();
		$raw = $this->validation(new MemberLogAppValidation, $this->request->getJsonRawBody());
		$data = MemberLogService::getList($raw);
		$d = [];
		foreach ($data as $key => $value) {
			$value->json_content = json_decode($value->json_content);
			$d[$key] = $value;
			$d[$key]->json_content->go_url = $value->json_content->go_url;
			$d[$key]->create_time = $this->getShowTime($value->create_time);
		}
		$count = MemberLogService::getList($raw, TRUE);
		$assign = [
			'total' => $count,
			'list' => $d,
		];

		return $this->echoJson($assign);
	}

	public function detailAction()
	{
		$this->getUser();
		$id = $this->dispatcher->getParam('id');
		$data = MemberLogService::getInfo($id);
		return $this->echoJson($data);
	}

	/**
	 * [doAction 浏览产生浏览记录]
	 * @return [type] [description]
	 */
	public function doAction()
	{
		$this->getUser();
		$raw = $this->validation(new MemberVisitValidation, $this->request->getJsonRawBody());
		$data = MemberLogService::do($raw);
		
		return $this->echoJson('ok');
	}

	/**
	 * [delAction 删除浏览记录 通过member_id,table_id,list_id]
	 * @return [type] [description]
	 */
	public function delAction()
	{
		$this->getUser();
		$raw = $this->validation(new MemberVisitValidation, $this->request->getJsonRawBody());
		$data = MemberLogService::del($raw);
		
		return $this->echoJson('ok');
	}

	/**
	 * [deleteAction 删除]
	 * @return [type] [description]
	 */
	public function deleteAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = MemberLogService::forever($raw->id);
		return $this->echoJson('ok');
	}

}